<template>
  <div>
    <h2 align="center">投资用户登录</h2>
    <table class="table table-bordered">
      <tr>
        <td>用户名:</td>
        <td>
          <input type="text" v-model="loginData.U_Name" >
        </td>
      </tr>

      <tr>
        <td>密码:</td>
        <td>
          <input type="password" v-model="loginData.U_Pwd" >
        </td>
      </tr>

      <tr>
        <td></td>
        <td>
          <input type="button" value="登录" class="btn btn-primary" @click="loginInfo">
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs,onMounted} from 'vue'

import axios from 'axios';

import {useRoute,useRouter} from 'vue-router'

let route = useRoute()
let router = useRouter()

//数据
let data = reactive({
  //登录数据
  loginData:{
    U_Name:'',
    U_Pwd:''
  }
})

//解构
let {loginData} = toRefs(data)

//登录
const loginInfo =()=>{
  //非空判断
  if(loginData.value.U_Name==""){
    return alert('用户名不能为空')
  }
  if(loginData.value.U_Pwd==""){
    return alert('密码不能为空')
  }
  //发送请求
  axios({
    url:'/api/Finance/User02Login',
    method:'get',
    params:loginData.value
  }).then(res=>{
    console.log(res);
    if(res.data.data==null){
      return alert('登录失败')
      
    }else{
      axios({
        url:'/api/Finance/User02Type',
        method:'get',
        params:{
          U_Id:res.data.data.U_Id
        }
      }).then(result=>{
        console.log(result);
        if(result.data.data==1){
          alert('欢迎管理员'+res.data.data.U_Name+'登录')
          router.push('/adminfinancelist')
        }else{
          alert('欢迎用户'+res.data.data.U_Name+'登录')
          router.push('/financelist')
        }
      }).catch(err=>{
        console.log(err);
        
      })
    }
  }).catch(err=>{
    console.log(err);
    
  })
}

</script>

<style scoped>

</style>